#!/bin/sh

PG_CONFIG=/usr/bin/pg_config
PSQL=/usr/bin/psql
DROPDB=/usr/bin/dropdb
CREATEDB=/usr/bin/createdb

USER=alexis
DB_NAME=agitum

SHARE_DIR=`$PG_CONFIG --sharedir`
CONTRIB=$SHARE_DIR/contrib
PROJECT=/home/alexis/workspace/agitum/database

echo '' >  __deploy__.log 

echo "dropdb $DB_NAME"
$DROPDB -U $USER $DB_NAME 2>&1 >> __deploy__.log

echo "createdb $DB_NAME"
$CREATEDB -U $USER $DB_NAME 2>&1 >> __deploy__.log

echo 'contrib'
$PSQL $DB_NAME -f $PROJECT/extension.sql 2>&1 >> __deploy__.log

$PSQL $DB_NAME -f $PROJECT/drop.sql 2>&1 >> __deploy__.log

echo 'functions'
$PSQL $DB_NAME -f $PROJECT/funct.sql 2>&1 >> __deploy__.log

echo 'tables structure'
$PSQL $DB_NAME -f $PROJECT/init.sql 2>&1 >> __deploy__.log

echo 'base data'
$PSQL $DB_NAME -f $PROJECT/data.sql 2>&1 >> __deploy__.log

#echo 'geo data'
#$PSQL $DB_NAME -f $PROJECT/data-geo.sql 2>&1 >> __deploy__.log

echo 'indexes'
$PSQL $DB_NAME -f $PROJECT/indexes.sql 2>&1 >> __deploy__.log
